package model;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.htmlparser.Parser;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.tags.TableColumn;
import org.htmlparser.util.NodeList;


public class TestResult {
	private String logName;
	private String url;

	public TestResult(String log){
		logName = log+"\\rational_ft_logframe.html";
	}

	public String setUrl(String path){
		return this.url;
	}

	public String[] getData(String type){
		try {
			HasAttributeFilter filter = new HasAttributeFilter("CLASS",type);
			Parser parser = new Parser(this.logName);
			parser.setEncoding("utf8");
			NodeList list = parser.extractAllNodesThatMatch(filter);
			String[] result = new String[list.size()];
			for (int i = 0; i < list.size(); i++) {
				result[i] = ((TableColumn)list.elementAt(i)).getFirstChild().getText();
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public boolean isPassed(){
		try {
			//HasAttributeFilter filter = new HasAttributeFilter("CLASS","note");
			HasAttributeFilter filter = new HasAttributeFilter("CLASS","pass");
            //File log = new File(this.logName);
			this.logName = "D:/StafrftLog/Logs/rational_ft_logframe.html" ;
			File log = new File(logName);
            if(!log.exists())
                System.out.println("file "+this.logName+" not exist");
            else
                System.out.println("file "+this.logName+" exist");
			Parser parser = new Parser(this.logName);
			NodeList list = parser.extractAllNodesThatMatch(filter);
			//String result = (((TableColumn)list.elementAt(list.size()-1)).getPreviousSibling().getPreviousSibling().getPreviousSibling().getPreviousSibling().getFirstChild().getText());
			String result = (((TableColumn)list.elementAt(list.size()-1)).getFirstChild().getText());
			if (result.equals("PASS")){
				return true;
			}else
				return false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	 public static void main(String[] args){
		 
	        TestResult ts = new TestResult("");
	        ts.isPassed();
	       
	    }


}
